//
//  RootViewController.swift
//  swiftDemo
//
//  Created by zhangjianyun on 17/6/28.
//  Copyright © 2017年 com.taihejiacheng. All rights reserved.
//

// 导入foudation 库
import Foundation
import UIKit

//定义一个类

class RootViewController: UIViewController,FontSizeChangeDelegate {
    
    var count = 0
    var myLabel: UILabel?
    
    
    override func viewDidLoad() {
        // 基类有的一个函数
        
        super.viewDidLoad()
        
        self.title = "哈哈哈"
        
        let barBtn = UIBarButtonItem(title: "next",style: UIBarButtonItemStyle.plain,target: self, action:#selector(self.didClickOnRightBarButton(sender:)))
        self.navigationItem.rightBarButtonItem = barBtn
        
        let rect = CGRect(x:0,y:100,width:320,height:44)
        myLabel = UILabel(frame:rect)
        myLabel!.text = "Hello World"
        myLabel!.backgroundColor = UIColor.blue
        self.view!.addSubview(myLabel!)
        
        let button = UIButton.init(type: UIButtonType.custom)
        button.frame = CGRect(x:0,y:200,width:100,height:40);
        button.setTitle("点我", for: UIControlState.normal)
        button.backgroundColor = UIColor.black
        button.addTarget(self, action: #selector(self.ClickMe(sender:)), for: UIControlEvents.touchUpInside)
        self.view!.addSubview(button)
    }
    
    func didClickOnRightBarButton(sender: UIBarButtonItem) {
        
        let second = SecondViewControlelr()
        self.navigationController?.pushViewController(second, animated: true)
    }

    func ClickMe(sender: UIButton) {
        count += 1
        myLabel?.text = "Hello World \(count) 次"
        print("点击了我\(count)次")
        
        let second = SecondViewControlelr()
        second.delegate = self
        self.navigationController?.pushViewController(second, animated: true)
    }

    func fontSizeChange(controller: SecondViewControlelr, fontSize: Int) {
        myLabel?.font = UIFont.systemFont(ofSize: CGFloat(fontSize))
    }
}

